package com.blank.serviceImpl;

import java.util.ArrayList;
import java.util.HashMap;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.blank.dao.ExpressDAO;
import com.blank.model.Express;
import com.blank.service.ExpressService;

@Service
public class ExpressServiceImpl implements ExpressService{
	
	@Resource
	private ExpressDAO expressDAO; 

	@Override
	public Express find(int id) {
		return expressDAO.find(id);
	}

	@Override
	public Express findByNu(String nu) {
		HashMap<Integer,Object> vars= new HashMap<>();
		vars.put(1,nu);
		@SuppressWarnings("unchecked")
		ArrayList<Express> expresses = (ArrayList<Express>) expressDAO.query("from Express where nu=?1", vars);
		return expresses.size()==0?null:expresses.get(0);
	}

	@Override
	public void add(Express express) throws Exception {
		expressDAO.add(express);
	}

	@Override
	public void update(Express exp) {
		expressDAO.save(exp);
		
	}

}
